define(['text!html/home.html', 'js/navigationManager', 'knockoutjs'], function (template, navigationManager, ko) {
    return new function () {
        var presenter = this;
        var searchPresenterPromise = curl('js/searchPresenter');
        var authenticationPresenterPromise = curl('js/authenticationPresenter');
        var aboutPresenterPromise = curl('js/aboutPresenter');

        function userViewModel() {
            var self = this;

            self.userName = ko.observable(null);

            authenticationPresenterPromise.then(function (authenticationPresenter) {
                authenticationPresenter.userLoaded.add(function (name) {
                    self.userName(name);
                });
            });
        };


        function menuViewModel() {

            this.search = function () {
                searchPresenterPromise.then(function (searchPresenter) {
                    searchPresenter.bind();
                });
            };

            this.profile = function () {
                authenticationPresenterPromise.then(function (authenticationPresenter) {
                    authenticationPresenter.authenticate();
                });
            };

            this.about = function () {
                aboutPresenterPromise.then(function (aboutPresenter) {
                    aboutPresenter.bind();
                });
            };
        }

        presenter.bind = function () {
            navigationManager.init(template, new userViewModel());
            ko.applyBindings(new menuViewModel(), $('#footer_menu').get(0));
            $('body').fadeIn();
        };
    };
});